/**
 * 
 */
package view_stunden;

import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import controller.StundenController;

import model.StundenModel;

/**
 * @author Schweingruber Roger
 * 
 */
public class EingabeMaske extends JPanel implements Observer {

	private ActionListener myActionListener;

	private StundenModel stundenModel;
	private StundenController stundenController;

	private JButton btnStart;

	private JButton btnStop;

	private JLabel lblProjektNummer;
	private JTextField txtProjektnummer;

	private JLabel lblKunde;
	private JTextField txtKunde;

	private Font fTitel;
	private Font fText;

	private JPanel pnlWidgets;
	private JPanel pnlUnterWidgets;

	/**
	 * Konstruktor
	 * 
	 * @param stundenModel
	 */
	public EingabeMaske(StundenModel stundenModel,
			StundenController stundenController) {
		super(new FlowLayout(FlowLayout.LEFT));

		this.stundenModel = stundenModel;
		this.stundenModel.addObserver(this);

		this.stundenController = stundenController;

		myActionListener = new MyActionListner();

		fTitel = new Font(Font.SANS_SERIF, Font.BOLD, 14);
		fText = new Font(Font.SANS_SERIF, Font.PLAIN, 12);

		initWidgets();

		addWidgets();
	}

	/**
	 * 
	 */
	private void initWidgets() {
		pnlWidgets = new JPanel(new GridLayout(0, 5, 5, 5));

		pnlUnterWidgets = new JPanel();
		pnlUnterWidgets.setLayout(new BoxLayout(pnlUnterWidgets,
				BoxLayout.PAGE_AXIS));

		btnStart = new JButton("Start");
		btnStart.setFont(fTitel);
		btnStart.addActionListener(myActionListener);

		btnStop = new JButton("Stop");
		btnStop.setFont(fTitel);
		btnStop.addActionListener(myActionListener);

		lblProjektNummer = new JLabel("Projekt Nr.");
		lblProjektNummer.setFont(fTitel);

		txtProjektnummer = new JTextField();
		txtProjektnummer.setFont(fText);

		lblKunde = new JLabel("Kunde");
		lblKunde.setFont(fTitel);

		txtKunde = new JTextField();
		txtKunde.setFont(fText);
	}

	/**
	 * 
	 */
	private void addWidgets() {
		pnlWidgets.add(Box.createHorizontalGlue());
		pnlWidgets.add(Box.createHorizontalGlue());
		pnlWidgets.add(Box.createHorizontalGlue());
		pnlWidgets.add(lblProjektNummer);
		pnlWidgets.add(lblKunde);

		pnlWidgets.add(btnStart);
		pnlWidgets.add(btnStop);
		pnlWidgets.add(Box.createHorizontalGlue());
		pnlWidgets.add(txtProjektnummer);
		pnlWidgets.add(txtKunde);

		pnlWidgets.setMaximumSize(pnlWidgets.getPreferredSize());

		pnlUnterWidgets.add(pnlWidgets);

		add(pnlUnterWidgets);

	}

	/**
	 * 
	 */
	@Override
	public void update(Observable o, Object arg) {
		if (o == stundenModel) {
			switch (arg.toString()) {

			}
		}
	}

	/**
	 * 
	 * @author Schweingruber Roger
	 * 
	 */
	private class MyActionListner implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			// Start
			if (e.getSource().equals(btnStart)) {
				stundenController.setStartZeit();
			}

			// Stop
			if (e.getSource().equals(btnStop)) {

				stundenController.setStopZeit();

			}

		}

	}
}
